package com.it135.citytraffic.controller;

import com.it135.citytraffic.pojo.result.Result;
import com.it135.citytraffic.pojo.dto.RoadJamCountReportDTO;
import com.it135.citytraffic.pojo.vo.EchartsSeriesVO;
import com.it135.citytraffic.pojo.vo.RoadJamCountReportVO;
import com.it135.citytraffic.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/report")
public class ReportController {

    @Autowired
    private ReportService reportService;
    @CrossOrigin
    @GetMapping("/road")
    public Result<RoadJamCountReportVO> getRoadJamReport( Integer crossing_id ,Integer status){
        List<RoadJamCountReportDTO> roadJamCount = reportService.getRoadJamCount(crossing_id,status);
        RoadJamCountReportVO roadJamCountReportVO = new RoadJamCountReportVO(new ArrayList<String>(),new ArrayList<Integer>());
        roadJamCount.forEach(item->{
            roadJamCountReportVO.getNameList().add(item.getName());
            roadJamCountReportVO.getCountList().add(item.getCount());
        });
        return Result.success(roadJamCountReportVO);
    }
    @CrossOrigin
    @GetMapping("/crossing")
    public Result<List<EchartsSeriesVO>> getCrossingReport(Integer crossingId,LocalDate beginDate, LocalDate endDate){

        return Result.success( reportService.getCrossingReport(crossingId,beginDate,endDate));
    }
}
